package com.earth;

import com.baomidou.mybatisplus.generator.FastAutoGenerator;
import com.baomidou.mybatisplus.generator.config.OutputFile;
import com.baomidou.mybatisplus.generator.config.rules.DbColumnType;
import com.baomidou.mybatisplus.generator.engine.FreemarkerTemplateEngine;

import java.sql.Types;
import java.util.Collections;

public class H2CodeGeneratorTest {

    public static void main(String[] args) {

        FastAutoGenerator.create("jdbc:mysql://localhost:3306/findlover?allowMultiQueries=true&autoReconnect=true&serverTimezone=Asia/Shanghai&useUnicode=true&characterEncoding=utf-8&useSSL=false", "root", "123456")
                .globalConfig(builder -> {
                    builder.author("zhengxincheng") // 设置作者
                            .outputDir(System.getProperty("user.dir") + "/digital-earth-portal/digital-earth-video/src/main/java"); // 指定输出目录
                })
                .dataSourceConfig(builder -> builder.typeConvertHandler((globalConfig, typeRegistry, metaInfo) -> {
                    int typeCode = metaInfo.getJdbcType().TYPE_CODE;
                    if (typeCode == Types.SMALLINT) {
                        // 自定义类型转换
                        return DbColumnType.INTEGER;
                    }
                    return typeRegistry.getColumnType(metaInfo);

                }))
                .packageConfig(builder -> {
                    builder.parent("com.earth") ;// 设置父包名
//                            .pathInfo(Collections.singletonMap(OutputFile.xml, System.getProperty("user.dir") + "/game-portal/game-portal-content/src/main/resource/mapper")) // 设置mapperXml生成路径
//                            .pathInfo(Collections.singletonMap(OutputFile.controller, System.getProperty("user.dir") + "/game-portal/game-portal-service/src/main/com/game/controller")) // 设置mapperXml生成路径
//                            .pathInfo(Collections.singletonMap(OutputFile.service, System.getProperty("user.dir") + "/game-portal/game-portal-service/src/main/com/game/service")) // 设置mapperXml生成路径
//                            .pathInfo(Collections.singletonMap(OutputFile.serviceImpl, System.getProperty("user.dir") + "/game-portal/game-portal-service/src/main/com/game/service/impl"));// 设置mapperXml生成路径
                })
                .strategyConfig(builder -> {
                    builder.addInclude("admin"); // 设置需要生成的表名

                })
                .templateEngine(new FreemarkerTemplateEngine()) // 使用Freemarker引擎模板，默认的是Velocity引擎模板
                .execute();
    }

}
